
from django.utils import timezone

class ChatMessage:
    def __init__(self, shop_id, username, message, message_id=None, expire_after=0, encrypted=False):
        self.shop_id = shop_id
        self.username = username
        self.message = message
        self.timestamp = timezone.now()
        self.message_id = message_id
        self.expire_after = expire_after
        self.encrypted = encrypted

    def to_dict(self):
        return {
            'username': self.username,
            'message': self.message,
            'timestamp': self.timestamp.strftime('%Y-%m-%d %H:%M:%S'),
            'messageId': self.message_id,
            'expireAfter': self.expire_after,
            'encrypted': self.encrypted
        }

    def __str__(self):
        return f"{self.username}: {self.message[:30]}"
